package com.x.mvp.widget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.ImageView;

import com.x.mvp.R;


public class AppProgress extends Dialog {

    private AppProgress(Context context, int theme) {
        super(context, theme);
    }

    public void onWindowFocusChanged(boolean hasFocus) {
        ImageView imageView = (ImageView) findViewById(R.id.progress_app_img);
        AnimationDrawable animationDrawable = (AnimationDrawable) getContext().getResources().getDrawable(R.drawable.appprogress);
        imageView.setBackgroundDrawable(animationDrawable);
        animationDrawable.start();
    }

    public static AppProgress getAppProgress(Context context, boolean cancelable,
                                             OnCancelListener cancelListener) {
        AppProgress appProgress = new AppProgress(context, R.style.Custom_Progress);
        appProgress.setTitle("");
        appProgress.setContentView(R.layout.progress_app);
        appProgress.setCancelable(cancelable);
        appProgress.setOnCancelListener(cancelListener);
        appProgress.getWindow().getAttributes().gravity = Gravity.CENTER;
        WindowManager.LayoutParams lp = appProgress.getWindow().getAttributes();
        lp.dimAmount = 0.2f;
        appProgress.getWindow().setAttributes(lp);
        return appProgress;
    }
}